/* Tour.java
 * 
 * The tour class compiles a list of events
 * that the tour is based on. It does the
 * checking on whether to accept events or not
 * and also says if the tour is valid. Tour
 * offerings are based off of a tour and its
 * events.
 * 
 * Greg Warner
 * Derek Dupuis
 * Michael Dixey
 * Alex Schwartz
 */

import java.util.*;

public class Tour
{
   //--------------------------names---------------------
   private String name;
   private String company;
   private float fitnessLevel;
   private int capacity;
   private boolean locked;
   private String city;
   private String state;
   //--------------------------lists---------------------
   private EventColl events;
   
   public Tour( String tN, String cN, int cap, String c, String s)
   {
      name = tN;
      company = cN;
      fitnessLevel = 0;
      capacity = cap;
      locked = false;
      events = new EventColl();
      city = c;
      state = s;
   }
   
   //-------------------accessor methods-----------------
   public String name() { return name; }
   
   public String company() { return company; }
   
   public int capacity() { return capacity; }
   
   public EventColl events() { return events; }
   
   public boolean locked() { return locked; }
   
   public String startPlace() { return events.startPlace(); }
   
   public String endPlace() { return events.endPlace(); }
   
   public float fitnessLevel() { return fitnessLevel; }
   
   public GregorianCalendar startTime() { return events.startTime(); }
   
   public GregorianCalendar endTime() { return events.endTime(); }
   
   public String city() { return city; }
   
   public String state() { return state; }
   
   //----------------------------------------------------
   
   //locks the tour so no events can be added
   public void lockTour()
   {
      locked = true;
   }
   
   public boolean addEvent( Event e )
   {
      if( events.add( e ) )
      {
         if( e.fitnessLevel() > fitnessLevel )
            fitnessLevel = e.fitnessLevel();
         return true;
      }
      return false;
   }
   
   //checks that the end location of the previous event must be equal to 
   //the start location of the next true = valid, false = invalid
   public boolean validityCheck()
   {
      Event first, second;
      
      for( int i = 0; i < events.size() - 1; i++ )
      {
         first = events.get( i );
         second = events.get( i + 1 );
         if( second.provider().service().type().compareTo( "travel" ) != 0 )
         {
            if( first.endPlace().compareTo( second.startPlace() ) != 0 )
               return false;
         }
      }
      return true;
   }
   
   /* Tour toString()
    * creates clean printout of all information inside the tour
    */
   public String toString()
   {
      //create a string representation of the tour object
      String s = String.format( "Tour: %s\t Company: %s\t " +
                               "Fitness Level: %d\t Capacity: %d\n",
                               name, company, (int)fitnessLevel, capacity );
      s = s + events.toString();
      return s;
   }
   
   /* Tour toStringBasic()
    * prints out all information on tour except the Events list
    */
   public String toStringBasic()
   {
      //create a string representation of the tour object
      String s = String.format( "Tour: %s\t Company: %s\t " +
                               "Fitness Level: %d\t Capacity: %d\n",
                               name, company, (int)fitnessLevel, capacity );
      return s;
   }
}
